package com.sojoys.artifact.factory.message;

import java.util.Arrays;

/**
 * @author : DengYing
 * @CreateDate : 2017年8月14日 上午11:53:18
 * @Description ：Please describe this document
 */
public abstract class IMessage {
	/**
	 * 包序
	 */
	private int serialNumber;
	/**
	 * 包长度
	 */
	private int length;
	/**
	 * 包类型
	 */
	private byte type;
	/**
	 * 消息码
	 */
	private short commandId;
	/**
	 * 状态码(0为正常 其他全为Error)
	 */
	private int status;
	/**
	 * 消息体
	 */
	private byte[] body = new byte[0];

	public int getSerialNumber() {
		return serialNumber;
	}

	public void setSerialNumber(int serialNumber) {
		this.serialNumber = serialNumber;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}
	
	public byte getType() {
		return type;
	}

	public void setType(byte type) {
		this.type = type;
	}

	public short getCommandId() {
		return commandId;
	}

	public void setCommandId(short commandId) {
		this.commandId = commandId;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public byte[] getBody() {
		return body;
	}

	public void setBody(byte[] body) {
		this.body = body;
	}

	public int getBodyLength(){
		return body == null ? 0 : body.length;
	}

	

	@Override
	public String toString() {
		return "IMessage [serialNumber=" + serialNumber + ", length=" + length + ", type=" + type + ", commandId="
				+ commandId + ", status=" + status + ", body=" + getBodyLength() + "]";
	}

	public abstract void parse(Object data);
}
